import sys
import subprocess
import os

def open_qt_designer():
    # 根据不同操作系统确定 Qt Designer 可执行文件的路径
    if sys.platform.startswith('win'):
        # Windows 系统
        designer_path = os.path.join(sys.exec_prefix, 'Lib', 'site-packages', 'qt6_applications', 'Qt', 'bin', 'designer.exe')
    elif sys.platform.startswith('darwin'):
        # macOS 系统
        designer_path = os.path.join(sys.exec_prefix, 'lib', 'python3.10', 'site-packages', 'qt6_applications', 'Qt', 'libexec', 'Designer.app', 'Contents', 'MacOS', 'Designer')
    elif sys.platform.startswith('linux'):
        # Linux 系统
        designer_path = os.path.join(sys.exec_prefix, 'lib', 'python3.10', 'site-packages', 'qt6_applications', 'Qt', 'bin', 'designer')
    else:
        print("不支持的操作系统")
        return

    # 检查 Qt Designer 可执行文件是否存在
    if os.path.exists(designer_path):
        try:
            # 启动 Qt Designer
            subprocess.Popen([designer_path])
            print("Qt Designer 已成功打开")
        except Exception as e:
            print(f"打开 Qt Designer 时出现错误: {e}")
    else:
        print(f"未找到 Qt Designer 可执行文件: {designer_path}")

if __name__ == "__main__":
    open_qt_designer()